package jwxx.server;
import java.sql.ResultSet;
import java.sql.SQLException;
import jwxx.server.DbOperator;
import jwxx.server.SUsingSkill;
public class SUsingSkillSql {
	private int n;
	private ResultSet rs;
	
	public int insert(SUsingSkill cb)throws SQLException{
		String sql = "insert into using_skill_table (id,fk_external_metal,fk_external_wood,fk_external_water,fk_external_fire,fk_external_earth,fk_intrinsic_metal,fk_intrinsic_wood,fk_intrinsic_water,fk_intrinsic_fire,fk_intrinsic_earth)values(?,?,?,?,?,?,?,?,?,?,?)";
		Object [] obj = new Object []{cb.getID(),cb.getExternalMetal(),cb.getExternalWood(),cb.getExternalWater(),cb.getExternalFire(),cb.getExternalEarth(),cb.getIntrinsicMetal(),cb.getIntrinsicWood(),cb.getIntrinsicWater(),cb.getIntrinsicFire(),cb.getIntrinsicEarth()};
				
		DbOperator db = new DbOperator();
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();	
		return n;
		}

	public int delete(int id)throws SQLException{
		String sql = "delete from using_skill_table where id=?";
		Object [] obj = new Object []{new Integer(id)};
		DbOperator db = new DbOperator();		
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();	
		return n;
	}	
	
	public int update(SUsingSkill cb)throws SQLException{
		String sql = "update using_skill_table set fk_external_metal=?,fk_external_wood=?,fk_external_water=?,fk_external_fire=?,fk_external_earth=?,fk_intrinsic_metal=?,fk_intrinsic_wood=?,fk_intrinsic_water=?,fk_intrinsic_fire=?,fk_intrinsic_earth=? where id=?";
		Object [] obj = new Object []{cb.getExternalMetal(),cb.getExternalWood(),cb.getExternalWater(),cb.getExternalFire(),cb.getExternalEarth(),cb.getIntrinsicMetal(),cb.getIntrinsicWood(),cb.getIntrinsicWater(),cb.getIntrinsicFire(),cb.getIntrinsicEarth(),new Integer(cb.getID())};
		DbOperator db = new DbOperator();	
		try	{
			n=db.executeUpdate(sql,obj);
			}catch(SQLException e){
				e.printStackTrace();
			}	
		db.close();	
		return n;		
	}	
	
	public ResultSet selectAllClass()throws SQLException{
		String sql="select * from using_skill_table";
		DbOperator db = new DbOperator();
		try{
			rs=db.executeQuery(sql, new Object[]{});
		}catch(SQLException e){
			e.printStackTrace();
		}	
		db.close();
		return rs;
	}
	
	public SUsingSkill selectById(int id)throws SQLException{		
		String sql2 = "select * from using_skill_table where id=?";
		DbOperator db = new DbOperator();
		SUsingSkill cb = new SUsingSkill();
		try{
			rs = db.executeQuery(sql2, new Object[]{new Integer(id)});
			while(rs.next()){			
				cb.setID(rs.getInt("id"));
				cb.setExternalMetal(rs.getInt("fk_external_metal"));
				cb.setExternalWood(rs.getInt("fk_external_wood"));
				cb.setExternalWater(rs.getInt("fk_external_water"));			
				cb.setExternalFire(rs.getInt("fk_external_fire"));
				cb.setExternalEarth(rs.getInt("fk_external_earth"));
				cb.setIntrinsicMetal(rs.getInt("fk_intrinsic_metal"));			
				cb.setIntrinsicWood(rs.getInt("fk_intrinsic_wood"));
				cb.setIntrinsicWater(rs.getInt("fk_intrinsic_water"));
				cb.setIntrinsicFire(rs.getInt("fk_intrinsic_fire"));			
				cb.setIntrinsicEarth(rs.getInt("fk_intrinsic_earth"));			
			}
		}catch(SQLException e){
			e.printStackTrace();
		}	
		db.close();
		return cb;
	
		}

}
